package com.health.ts.service.patientview;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.health.ts.dao.patientview.StDrugOrdersMapper;
import com.health.ts.entity.patientview.StDrugOrders;

/**
 * <p>
 * 药品医嘱表 服务实现类
 * </p>
 *
 * @author ts
 * @since 2017-09-15
 */
@Service
public class StDrugOrdersService extends ServiceImpl<StDrugOrdersMapper, StDrugOrders> {
	
	/**
	 * 根据患者ID获取药品医嘱列表
	 * @param patientId
	 * @return
	 */
	public Map<String,Object> getDrugOrders(String patientId){
		Map<String,Object> result = new HashMap<String,Object>();
		QueryWrapper<StDrugOrders> wrapper = new QueryWrapper<StDrugOrders>();
		wrapper.eq("patient_id", patientId);
		wrapper.orderByDesc("start_date");
		List<StDrugOrders> drugOrders = this.list(wrapper);
		//长期医嘱
		List<StDrugOrders> longTermOrders = new ArrayList<StDrugOrders>();
		//临时医嘱
		List<StDrugOrders> tempOrders = new ArrayList<StDrugOrders>();
		for(StDrugOrders temp : drugOrders){
			if(temp.getEndDate()!=null){
				longTermOrders.add(temp);
			}else{
				tempOrders.add(temp);
			}
		}
		result.put("longTerm", longTermOrders);
		result.put("temp", tempOrders);
		return result;
	}
}
